from typing import Self
import pygame
import data_inputer
from node_effector import NodeEffector
from pygame_single import Pygame_Single
class MapManager:
    instance=None
    node_effectors:dict
    line_rects:dict
    _map_img_name="init.png"
    def __new__(cls, *args, **kw) -> Self:
        if(cls.instance is None):
            cls.instance = object.__new__(cls)
        return cls.instance
    def ReFresh(self):
        Pygame_Single.instance.Refresh()
    def __init__(self,node_datas:dict) -> None:
        for node in node_datas.values():
            NodeEffector(node)#初始化节点效果器
        self.node_effectors=NodeEffector.Static_Dict
        self.line_rects=NodeEffector.Static_Lines_Dict
    def LoadMap(self):
        NodeEffector.Static_DrawMap()
        # pygame.image.save(Pygame_Single.instance.screen,self._map_img_name)
        # Pygame_Single.instance.screen=pygame.image.load(self._map_img_name).convert()
        self.ReFresh()
    def Clear(self):
        Pygame_Single.instance.screen.blit(pygame.image.load(self._map_img_name).convert(), (0, 0))
        self.ReFresh()
    def DrawRoad(self,nodes_id:list):
        self.Clear()
        for i in range(len(nodes_id)-1):
            NodeEffector.Static_DrawOneLine(nodes_id[i],nodes_id[i+1])
        self.ReFresh()
        
    